package com.wz.jiangsu.controller;

import cn.hutool.json.JSONUtil;
import com.wz.jiangsu.annotation.TestAnnotation;
import com.wz.jiangsu.bean.Event;
import com.wz.jiangsu.exception.CustomException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @program: wz
 * @author: wangzhou
 * @create: 2023-12-03 21:44
 * @description:
 **/

@RestController
@Slf4j
public class TestBController {


    /**
     * JsonProperty 的作用是反序列化接收值和序列化的值 都是使用 JsonProperty 的 value 的值
     * @param event
     * @return
     */
    @PostMapping("/test/testJsonProperty")
    public Event testJsonProperty(@RequestBody Event event){
        String jsonStr = JSONUtil.toJsonStr(event);
        log.error("jsonStr={}",jsonStr);
        // 反序列化
        Event bean = JSONUtil.toBean(jsonStr, Event.class);
        return bean;
    }

    @GetMapping("/test/testA/{id}")
    @TestAnnotation("my name is wangzhou，how old are you")
    public String testA(@PathVariable("id") Integer id){

        if(id instanceof Integer){
            throw new CustomException("11",500);
        }


        System.out.println(id);




        return String.valueOf(id);
    }
}
